package com.wxp.demo09.system;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.wxp.demo09.R;
import com.wxp.demo09.system.receiver.TimeReceiver;

/**
 * 2.1 系统广播-接收分钟到达广播
 */
public class SystemMinuteActivity extends AppCompatActivity {

    private TimeReceiver timeReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_system_minute);
        this.setTitle("2.1 系统广播-接收分钟到达广播");
    }

    @Override
    protected void onStart() {
        super.onStart();
        // 创建一个分钟变更的广播接收器
        timeReceiver = new TimeReceiver();
        //定义分钟变更过滤器
        IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
        //注册接收器
        this.registerReceiver(timeReceiver, filter);
    }

    @Override
    protected void onStop() {
        super.onStop();
        //解除注册
        this.unregisterReceiver(timeReceiver);
    }

}